package com.cbt.cbtBlog.runner;

import com.cbt.cbtBlog.util.ConstantInfo;
import com.cbt.cbtBlog.util.StringUtil;
import java.io.File;
import javax.servlet.ServletContextEvent;
import javax.servlet.ServletContextListener;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Component;

@Component
public class CreateUploadPathRunner implements ServletContextListener {
   @Value("${upload-path}")
   private String basepath;

   public void contextInitialized(ServletContextEvent sce) {
      if (StringUtil.checkNull(this.basepath)) {
         this.basepath = "/www/wwwroot/file";
      }

      File f1 = new File(this.basepath, "blog_files");
      if (!f1.exists()) {
         f1.mkdirs();
      }

      ConstantInfo.BASEPATH = this.basepath;
   }
}
